package com.sumainfor.zuul.conf;

import com.sumainfor.common.Constants;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author PuaChen
 * @Create 2018-11-16 15:12
 */
public class ServerProviderInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String auth = request.getHeader("auth");
        if (StringUtils.isBlank(auth) || !auth.equals(Constants.AUTH)) {
            response.sendError(401, "没有权限访问");
            return false;
        }
        return true;
    }
}
